package com.sj.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sj.entity.Tag;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author 小七
 * @since 2021-07-30
 */
@Repository
public interface TagMapper extends BaseMapper<Tag> {

    /**
     * 根据标签id查询标签信息
     *
     * @param id 标签id
     * @return 标签信息
     */
    @Select("select * from tag where id in (select tag_id from blog_tag where blog_id = #{blogId})")
    List<Tag> getTagListByBlogId(@Param("blogId") Integer id);

    /**
     * 查询标签下的播客数
     *
     * @param id 标签id
     * @return 播客数
     */
    @Select("select count(*) from blog_tag where tag_id = #{tagId}")
    Integer getCountTagBindBlog(@Param("tagId") Integer id);
}
